<?php
class Sysadminmodel extends Model {
	function Sysadminmodel(){
		parent::Model();
	}
	function show_dept() {
		$this->db->select('*');
		$this->db->from('dept');
		$this->db->order_by('dept_id','desc');
		return $this->db->get();
	}
	function show_id_user() {
		$this->db->select('*');
		$this->db->from('user');
		$this->db->order_by('user_id','desc');
		$this->db->limit('1');
		return $this->db->get();
	}
	function insert_user($insert_user) {
		$this->db->insert('user',$insert_user);
	}
	
	
	//transaction log
	function insert_log($insert_log) 
	{
		$this->db->insert('transaction_log',$insert_log);
	}
	function show_id_trans_log() 
	{
		$this->db->select('*');
		$this->db->from('transaction_log');
		$this->db->order_by('id','desc');
		
		return $this->db->get();	
	}
	function show_user_log($id) {
		$this->db->select('*');
		$this->db->from('user');
		$this->db->where('user_id',$id);
		
		return $this->db->get();
	}
	function show_all_translog($user_id) {
		$this->db->select('a.notes,a.datetime,a.ip,b.name');
		$this->db->from('transaction_log a,user b');
		$this->db->where('a.user_id = b.user_id');
		$this->db->where('name',$user_id);
		$this->db->order_by('id','desc');
		
		return $this->db->get();
	}
	
	//manage user
	function count_all_num_rows() {
		return $this->db->count_all('user');
	}
	function show_all_manage($offset) {
		$this->db->select('a.user_id,a.name,a.email,a.mandiri_id,a.status,b.dept_name');
		$this->db->from('user a,dept b');
		$this->db->where('a.dept_id = b.dept_id');
		$this->db->order_by('user_id','desc');
		$this->db->limit(20,$offset);
		
		return $this->db->get();
	}
	function delete_user($id) {
		$this->db->where('user_id',$id);
		$this->db->delete('user');
	}
	
	function get_user_by_id($id) {
		$this->db->select('*');
		
		$this->db->where('user_id',$id);
		return $this->db->get('user');
	}
	function update($id,$users) {
		$this->db->where('user_id',$id);
		$this->db->update('user',$users);
		
		
	}
	function valid_entry($name)
	{
		$this->db->where('name', $name);
		
		$query = $this->db->get('user')->num_rows();
						
		if($query > 0)
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	
	function cek_mail($mail) {
		$this->db->where('email',$mail);
		
		
		$query = $this->db->get('user')->num_rows();
						
		if($query > 0)
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	
/* UPREG
---------------------------------------------------------------------------------------*/
	function insert_upreg($upreg) {
		$this->db->insert('user',$upreg);
		
	}
	
	function show_enkrip($user_id) {
		$this->db->select('*');
		$this->db->from('user');
		$this->db->where('user_id',$user_id);
		
		return $this->db->get();
	}
	
	function show_user_upreg($ao) {
		$this->db->select('a.*,b.dept_name');
		$this->db->from('user a, dept b');
		$this->db->where('a.dept_id = b.dept_id');
		$this->db->where('pass2',$ao);
		$this->db->order_by('user_id','desc');
		
		return $this->db->get();
	}
	
	function show_upreg_data ($id_verif) {
		$this->db->select('*');
		$this->db->from('user');
		$this->db->where('user_id',$id_verif);
		
		return $this->db->get();
	}
	
	function update_verif($id,$verif) {
		$this->db->where('user_id',$id);
		$this->db->update('user',$verif);
		
		
	}
	
	
	
}
?>